package cc.avatar.util;

import java.util.Calendar;
import java.util.Date;

public class DateUtil {
	 public static Date getDateBeforeNow(int days) {   
         Calendar now = Calendar.getInstance();   
         now.set(Calendar.DATE, now.get(Calendar.DATE) - days + 1);   
         now.set(Calendar.HOUR_OF_DAY, 0);
         now.set(Calendar.MINUTE , 0);
         now.set(Calendar.SECOND , 0);
         now.set(Calendar.MILLISECOND, 0);
         return now.getTime();   
     }   
	 
	 public static Date getNextDay(Date d){
		 Calendar c = Calendar.getInstance();  
		 c.setTime(d);
		 c.add(Calendar.DAY_OF_MONTH, 1);
		 return c.getTime();		 
	 }
	 public static Date getBeginningOfMonth(int year, int month){
		 Calendar c = Calendar.getInstance();  
		 c.set(Calendar.YEAR, year);
		 c.set(Calendar.DAY_OF_MONTH, 1);
		 c.set(Calendar.MONTH, month - 1);
         c.set(Calendar.HOUR_OF_DAY, 0);
        
         c.set(Calendar.MINUTE , 0);
         c.set(Calendar.SECOND , 0);
         c.set(Calendar.MILLISECOND, 0);
		 return c.getTime();
	 }
	 
	 public static Date addOneMonth(Date date){
		 Calendar c = Calendar.getInstance();  
		 c.setTime(date);
		 c.add(Calendar.MONDAY, 1);
		 return c.getTime();
	 }
	 
	 public static Date addOneDay(Date date){
		 Calendar c = Calendar.getInstance();  
		 c.setTime(date);
		 c.add(Calendar.DAY_OF_YEAR, 1);
		 return c.getTime();
	 }	 
	 
	 public static void main(String[] arg){
		 System.out.println(System.getProperty("file.encoding"));
	 }

}
